﻿using System;
using System.Collections.Generic;
using HYElectricKernel;

namespace HYRElectric.LightningCalculation
{
	public class LightningCalculator
	{
		public static void CalculateLightning(double Ae, double k, double Ng, ref double N)
		{
			N = Ae * k * Ng;
		}

		public static void FormulaMethodCalculateArea(EnvironmentalFactors ef, double length, double width, double Height, ref double area, ref List<string> aeCalculateFormulaDetailed)
		{
			aeCalculateFormulaDetailed.Clear();
			double num = 0.0;
			double num2 = 100.0;
			length = Common.FeetToMM(length) / 1000.0;
			width = Common.FeetToMM(width) / 1000.0;
			Height = Common.FeetToMM(Height) / 1000.0;
			double num3 = length * width;
			double num4 = 2.0 * (length + width);
			double num5 = Height * (num2 * 2.0 - Height);
			double num6 = Math.Sqrt(num5);
			if (Geometry.LessThan(Height, num2))
			{
				aeCalculateFormulaDetailed.Add("等效面积Ae为: H<100m,");
				switch (ef)
				{
				case EnvironmentalFactors.EF_Without:
					num = (num3 + num4 * num6 + Math.PI * num5) / 1000000.0;
					aeCalculateFormulaDetailed.Add("Ae =[L*W+2*(L+W)*SQRT(H*(200-H))+3.1415926*H(200-H)]*10^(-6) = " + num.ToString());
					break;
				case EnvironmentalFactors.EF_LowerThanOrEqual:
					num = (num3 + num4 / 2.0 * num6 + Math.PI * num5 / 4.0) / 1000000.0;
					aeCalculateFormulaDetailed.Add("Ae =[L*W+(L+W)*SQRT(H*(200-H))+3.1415926*H(200-H)/4]*10^(-6) = " + num.ToString());
					break;
				case EnvironmentalFactors.EF_HigherThan:
					num = num3 / 1000000.0;
					aeCalculateFormulaDetailed.Add("Ae =L*W*10^(-6) = " + num.ToString());
					break;
				}
			}
			else
			{
				aeCalculateFormulaDetailed.Add("等效面积Ae为: H>=100m,");
				switch (ef)
				{
				case EnvironmentalFactors.EF_Without:
					num = (num3 + num4 * Height + Math.PI * Math.Pow(Height, 2.0)) / 1000000.0;
					aeCalculateFormulaDetailed.Add("Ae =[L*W+2*H*(L+W)+3.1415926*H^2]*10^(-6) = " + num.ToString());
					break;
				case EnvironmentalFactors.EF_LowerThanOrEqual:
					num = (num3 + num4 / 2.0 * Height + Math.PI * Math.Pow(Height, 2.0) / 4.0) / 1000000.0;
					aeCalculateFormulaDetailed.Add("Ae =[L*W+H*(L+W)+3.1415926*H^2/4]*10^(-6) = " + num.ToString());
					break;
				case EnvironmentalFactors.EF_HigherThan:
					num = num3 / 1000000.0;
					aeCalculateFormulaDetailed.Add("Ae =L*W*10^(-6) = " + num.ToString());
					break;
				}
			}
			area = num;
		}

		public static double CalculateOffset(double elevation)
		{
			double num = Common.MMToFeet(100000.0);
			double result;
			if (Geometry.LessThan(elevation, num))
			{
				result = Math.Sqrt((num * 2.0 - elevation) * elevation);
			}
			else
			{
				result = elevation;
			}
			return result;
		}
	}
}
